import mongoose from 'mongoose';
import { formatDateByNow } from '~/utils/util.date';

export interface IUserFastLink extends mongoose.Document {
	userId: mongoose.Schema.Types.ObjectId;
	icon: string;
	name: string;
	description: string;
	type: string;
	resourceId: mongoose.Schema.Types.ObjectId;
	createdAt?: string;
	updatedAt?: string;
}

// 用户快速链接
const UserFastLinkSchema = new mongoose.Schema<IUserFastLink>(
	{
		userId: {
			type: mongoose.Schema.Types.ObjectId,
			required: true,
		},
		icon: {
			type: String,
			required: true,
		},
		name: {
			type: String,
			required: true,
			unique: true,
		},
		description: {
			type: String,
			required: true,
		},
		type: {
			type: String,
			enum: ['resource', 'custom'],
		},
		resourceId: {
			type: mongoose.Schema.Types.ObjectId,
		},
		createdAt: {
			type: String,
			default: formatDateByNow(),
		},
		updatedAt: {
			type: String,
			default: formatDateByNow(),
		},
	},
	{
		collection: 'user_fast_links',
	}
);

export const UserFastLinkModel = mongoose.model('UserFastLink', UserFastLinkSchema);
